package com.woniu.new_orange.service_model_gao.controller;

import com.woniu.new_orange.entity.Complaint;
import com.woniu.new_orange.service_model_gao.service.ComplaintService;
import com.woniu.new_orange.service_model_gao.vo.ComplaintVo;
import com.woniu.new_orange.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Program: new_orange->ComplaintController
 * @Description: 投诉表controller
 * @Author: donghang
 * @Date: 2023-01-14 09:59
 * @Version： 1.0
 **/
@RestController
@RequestMapping("/complaint")
@Api(value = "投诉操作",tags="用户投诉")
public class ComplaintController {
    @Autowired
    private ComplaintService complaintService;

    @GetMapping("{id}")
    @ApiOperation(value = "获取投诉表全部数据",notes = "获取投诉表全部数据返回给前端页面展示")
    public Result queryAll(@PathVariable long id){
        List<ComplaintVo> complaints = complaintService.selectAll(id);
        return Result.ok().data("complaintList",complaints);
    }

    @GetMapping("")
    @ApiOperation(value = "获得所有用户投诉数据",notes = "从数据库提取所有投诉数据展示")
    public Result getAll(){
        List<ComplaintVo> complaintVos = complaintService.selectAll2();
        return Result.ok().data("allcomplaintList",complaintVos);
    }

    @PostMapping("")
    @ApiOperation(value = "向投诉表中添加数据",notes = "从前端页面获取数据后存入数据库中")
    public Result add(@RequestBody Complaint record){
        int i = complaintService.insertSelective(record);
        return Result.ok();
    }
}
